/***************************************************************************
 *   Copyright (C) 2007 by Ziman & Xloverin                                *
 *   ziman@centrum.sk, xloverin@gmail.com                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef LINE_H
#define LINE_H

#include <QByteArray>
#include <QString>
#include <QList>

#define LINE_TYPE_COUNT 14

// Vybrane subtypy
#define AFK_START	0
#define AFK_END  	1

// CMD_ subtypy: CMD_X -- zaciatok vypisu prikazu; CMD_X+1 -- koniec vypisu
#define CMD_READ	0
#define CMD_LOOK	2
#define CMD_STATUS	4
#define CMD_CMODE	6
#define CMD_MACRO	8
#define CMD_EDITOR	10

class TagCache;
/**
 * Zapuzdruje riadok dat prijatych od servera, vratane tagu.
 * @author Ziman & Xloverin <ziman@centrum.sk, xloverin@gmail.com>
 */
class Line {
	
	public:
		
		/// Typ riadka.
		enum Type {
			Unknown		= 0,
   			Say			= 1,
	  		Tell		= 2,
	 		Shout		= 3,
			Hug			= 4,
   			Kiss		= 5,
	  		Movement	= 6,
   			Fauna		= 7,
	  		System		= 8,
	 		Gossip		= 9,
			Login		= 10,
   			Afk			= 11,
	  		Command		= 12,	// vystup prikazu
	 		Action		= 13
		};
		
		struct Tag {
			
			/// Typ riadka.
			Type type;
			
			/// Subtyp riadka.
			int subtype;
			
			/// Riadok obsahuje znak BEL.
			bool BEL;
			
			/// Captury z regexpov.
			QString arg[3];
			
			/// Nejaky defaultny nulujuci kontruktor.
			Tag();
		};
		
		static const char *const typeNames[LINE_TYPE_COUNT];
		
		Line(QByteArray data, TagCache *tagCache);
		~Line();
		
		/// Vrati tag.
		const Tag &tag() const;
		
		/// Vrati bezfarebny text.
		const QString &plain() const;
		
		/// Vrati binarne data asociovane s riadkom.
		const QByteArray &binary() const;
		
		/// Vrati cinitela deja (ak je definovany).
		const QString &subject() const;
		
		/// Vrati predmet deja (ak je definovany).
		const QString &object() const;
		
	private:
		
		/// Data celeho riadka.
		QByteArray m_binary;
		QString m_plain;
		
		/// Typ riadka.
		Tag m_tag;
		
		/// Hovoriaci a posluchac; definovanost zavisi na type riadka.
		QString m_subject;
		QString m_object;

		/// Vykona samotne otagovanie.
		void determineType(TagCache &tagCache);		
};

#endif
